//分类的仓库
import { defineStore } from "pinia";
//引入API
import { reqC1, reqC2, reqC3 } from "@/api/product/attr";
import type { CategoryList } from "@/api/product/attr/interface";
import type { CategoryState } from '@/stores/interface/index';
const useCategoryStore = defineStore('Category', {
    //存储数据地方
    state(): CategoryState {
        return {
            //存储一级分类的数据
            c1Arr: [],
            c1Id: '',
            //存储二级分类的数据
            c2Arr: [],
            c2Id: '',
            //存储三级分类的数据
            c3Arr: [],
            c3Id: '',
        }
    },
    //actions
    actions: {
        async getC1() {
            const result: CategoryList = await reqC1();
            this.c1Arr = result;
        },
        async getC2(){
            const result: CategoryList = await reqC2(this.c1Id as number);
            this.c2Arr = result;
        },
        async getC3(){
            const result: CategoryList = await reqC3(this.c2Id as number);
            this.c3Arr = result;
        }
    },
    getters: {

    }
})

export default useCategoryStore;